using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ModelView : MonoBehaviour
{
    public int Round;

    public float MoveSpeed = 1.5f;
    void Start()
    {

    }

    public IEnumerator Move()
    {
        while (true)
        {
            RaycastHit2D hit = CheckAround(Vector3.up);

            if (hit.transform == null)
            {
                Vector3 pos = transform.position;
                pos.y = pos.y + Time.deltaTime * MoveSpeed;
                if (pos.y >= 3)
                {
                    pos.y = 3;
                }
                transform.position = pos;
            }
            yield return null;
        }
    }

    public RaycastHit2D CheckAround(Vector3 dir)
    {
        Debug.DrawLine(transform.position + dir * 0.8f, transform.position + dir, Color.red);
        return Physics2D.Linecast(transform.position + dir * 0.8f, transform.position + dir, LayerMask.GetMask("Model"));
    }

    public void BeginMove()
    {
        StartCoroutine(Move());
    }
}
